package com.uscn.java.util;

import java.io.*;
import java.util.*;

public class MyFileUtil {

	private String file_name = null;
	private ObjectOutputStream objectOutput;
	private BufferedOutputStream bufOutput;
	private StringBuffer file_containt;

	public void setFileName(String file_name) {
		this.file_name = file_name;
	}


	public StringBuffer getFileContaint() {
		return file_containt;
	}

	public void setFileContaint(StringBuffer file_containt) {
		this.file_containt = file_containt;
	}
	
	public void useObjectOutputStream(String inputString) {
		String temp = inputString;

		try {
			objectOutput = new ObjectOutputStream(new FileOutputStream(file_name));
			objectOutput.writeObject(temp);
			objectOutput.close();
		} catch (IOException e) {

		}
	}

	public void useDataOutputStream(String inputString) {
		String temp = inputString;
		try {
			DataOutputStream dos = new DataOutputStream(new FileOutputStream(file_name));
			// dos.writeChars(temp); //16 bits
			dos.writeBytes(temp); // 8 bits
			dos.close();
		} catch (IOException e) {

		}
	}

	public void useFileOutputStream(String inputString) {
		String temp = inputString;

		try {

			FileOutputStream fos = new FileOutputStream(file_name);
			for (int i = 0; i < temp.length(); i++) {
				fos.write(temp.charAt(i));
			}

			fos.close();
		} catch (IOException e) {

		}
	}

	public void useBufferedOutputStream(String inputString) {
		String temp = inputString;

		try {
			bufOutput = new BufferedOutputStream(new FileOutputStream(file_name));
			for (int i = 0; i < temp.length(); i++) {
				bufOutput.write(temp.charAt(i));
			}
			bufOutput.flush();
			bufOutput.close();
		} catch (IOException e) {

		}
	}

	public void useBufferedWriter(String inputString) {
		String temp = inputString;

		try {
			FileWriter fw = new FileWriter(file_name);
			BufferedWriter bfw = new BufferedWriter(fw);
			bfw.write(temp);
			bfw.flush();
			bfw.close();
		} catch (IOException e) {

		}
	}
}
